package com.zhipu.balance.utils.dialog

import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.AppUtils
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.enums.PopupAnimation
import com.zhipu.balance.mobile.temporaryClass.VersionUpdate
import com.zhipu.balance.pop.GeneralPurposePopup
import com.zhipu.balance.pop.UpdatePopup
import com.zhipu.balance.utils.CommonUtils
import com.zhipu.balance.utils.EditionUtils
import com.zhipu.balance.utils.InitializeUtils

object CommonDialog {

    var mGeneralPurposePopup: GeneralPurposePopup? = null
    /**
     * 通用提示
     */
    fun showGP(characters: String?) {
        mGeneralPurposePopup = GeneralPurposePopup(characters!!)
        XPopup.Builder(ActivityUtils.getTopActivity())
            .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
            .autoOpenSoftInput(false)
            .asCustom(mGeneralPurposePopup)
            .show();
    }

    /**
     * 关闭弹框
     */
    fun dismissGP(){
        mGeneralPurposePopup?.dismiss()
    }

    var mUpdatePopup : UpdatePopup? = null
    fun showAccordingToUpdate(mVersionUpdate : VersionUpdate){
        //获取 App 版本码
        val mAppVersionCode = AppUtils.getAppVersionCode()
        val local: Int? = mVersionUpdate.versionName?.let { EditionUtils.compareVersion(it, AppUtils.getAppVersionName()) }
        if (mVersionUpdate.versionCode > mAppVersionCode && local == 1) {
            mUpdatePopup = UpdatePopup(mVersionUpdate)
            XPopup.Builder(ActivityUtils.getTopActivity())
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .autoOpenSoftInput(false)
                .asCustom(mUpdatePopup)
                .show();
        }else{
            InitializeUtils.getDefaultMaker()?.show("已经是最新版本!")
        }

    }

}